'''
Created on 07/06/2010

@author: Will
'''
from pyglet.gl import *
import math





class Camera(object):
    

    
    def __init__(self, win, x=0.0, y=0.0, rot=0.0, zoom=400.0):
        
        
            self.win = win
            self.x = x
            self.y = y
            self.rot = rot
            self.zoom = zoom
            self.targetZoom = zoom
            self.setted = True


    def worldProjection(self):
        
        if math.fabs(self.zoom - self.targetZoom) > 1: 
            self.zoom = self.zoom + (self.targetZoom - self.zoom)*0.1
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(self.x - self.zoom * self.win.width  / self.win.height,
                   self.x + self.zoom * self.win.width  / self.win.height,
                   self.y - self.zoom,
                   self.y + self.zoom)


    def hudProjection(self):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0,self.win.width, 0,self.win.height)
        
        
        
        
        
    
        
    def on_mouse_motion(self, x, y, dx, dy):    
        pass        
        

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        pass     

    def on_mouse_press(self, x, y, button, modifiers):
        pass

    def on_mouse_scroll(self,x, y, scroll_x, scroll_y):
        self.targetZoom = self.targetZoom - scroll_y*3
        if self.targetZoom < 200:
            self.targetZoom = 200
        if self.targetZoom > 2000:
            self.targetZoom = 2000